import java.lang.reflect.Field;
import java.util.Arrays;

public class Main {

    public static void main(String[] args) {
        String test1 = "3{a}2{bc}";
        String test2 = "3{a2{c}}";
        String test3 = "2{abc}3{cd}ef";
        System.out.println(deComprise(test1));
        System.out.println(deComprise(test2));
        System.out.println(deComprise(test3));
    }

    public static String deComprise(String s) {
        return process(s.toCharArray(), 0).str;
    }

    public static class ReturnData {
        int end;
        String str;
        public ReturnData(int end, String str) {
            this.end = end;
            this.str = str;
        }
    }

    public static ReturnData process(char[] cs, int index) {
        StringBuilder sb = new StringBuilder();
        int times = 0;
        while (index < cs.length && cs[index] != '}') {
            if (cs[index] == '{') {
                ReturnData rd = process(cs, index + 1);
                sb.append(countTimesString(rd.str, times));
                times = 0;
                index = rd.end + 1;
            } else {
                if (cs[index] >= '0' && cs[index] <= '9') {
                    times = times * 10 + cs[index] - '0';
                } else {
                    sb.append(cs[index]);
                }
                index++;
            }
        }
        return new ReturnData(index, sb.toString());
    }

    public static String countTimesString(String s, int times) {
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < times; i++) {
            sb.append(s);
        }
        return sb.toString();
    }

}
